import { t } from "@/locales";
import {FormRule, PrimaryTableCol, SelectProps, Tag} from "tdesign-vue-next";
import {fileView} from "@/api/upload";
import SImageView from "@/components/s-image-view/index.vue";

/**
 * 搜索表单项
 */
export const searchParams: SearchParamsProps[] = [
    {
        label: t('pages.motion.name'),
        key: 'name',
    },
    {
        label: t('pages.motion.beneficialPosition'),
        key: 'beneficialPosition',
    },
];

/**
 * 表格列
 */
export const columns: PrimaryTableCol[] = [
    {
        title: t('pages.motion.name'),
        ellipsis: true,
        align: 'center',
        colKey: 'name',
    },
    {
        title: t('pages.motion.type'),
        ellipsis: true,
        align: 'center',
        colKey: 'type',
        cell: (h, {row}) => {
            if (row.type == 0) {
                return t('pages.motion.typeOption.sports')
            } else if (row.type == 1) {
                return t('pages.motion.typeOption.motion')
            } else {
                return t('pages.motion.typeOption.sportsNew')
            }
        }
    },
    {
        title: t('pages.motion.applicableAge'),
        ellipsis: true,
        align: 'center',
        colKey: 'applicableAge',
        cell: (h, {row}) => {
            if (row.applicableAge) {
                return h(SImageView, { images: [fileView(row.applicableAge)], width: 45, height: 45 });
            }
            return '-';
        }
    },
    {
        title: t('pages.motion.beneficialPosition'),
        ellipsis: true,
        align: 'center',
        colKey: 'beneficialPosition',
    },
    {
        title: t('pages.motion.introduction'),
        ellipsis: true,
        align: 'center',
        colKey: 'introduction',
    },
    {
        title: t('pages.motion.status'),
        ellipsis: true,
        align: 'center',
        colKey: 'status',
        cell: (h, {row}) => h(Tag,
            { theme: row.status == 0  ? 'primary' : row.status == 1  ? 'success' : 'warning' },
            row.status == 0 ? '未发布' : row.status == 1 ? '已发布' : '已撤销'
        )
    },
    {
        title: t('pages.motion.remarks'),
        ellipsis: true,
        align: 'center',
        colKey: 'remarks',
    },
];

/**
 * 表单校验规则
 */
export const rules: Record<string, FormRule[]> = {
    name: [{required: true, message: t('pages.motion.required.name'), type: 'error', trigger: 'all'}],
    type: [{required: true, message: t('pages.motion.required.type'), type: 'error', trigger: 'all'}],
    introduction: [{required: true, message: t('pages.motion.required.introduction'), type: 'error', trigger: 'blur'}],
}

export const typeOptions: SelectProps['options'] = [
    {
        label: t('pages.motion.typeOption.sports'),
        value: 0
    },
    {
        label: t('pages.motion.typeOption.motion'),
        value: 1
    },
    {
        label: t('pages.motion.typeOption.sportsNew'),
        value: 2
    },
];
